<?php
	include("mysql_connect.php");
	include("error/upload.php");
	
	$xmlstring = '
	<AccountInfo UserName="rafale@thetigerparty.com" Password="aaa" Name="Rafale Chang" Level="Developer" Organization="BeSpoke" />';

	function XMLCharEncode( $Subject )
	{
		$Serach  = array( "<", ">", "&", "'","\"" );
		$Replace = array( "&lt;","&gt;","&amp;","&apos;","&quot;");
		return str_replace($Serach, $Replace, $Subject);
	}
	//----------------------------------------------------------
	// BeSpoke API - User Info Node
	// Author  : Yu-Cheng Fan
	// Created : 2012/09/11
	// Version : V1.0.0.0
	// Note    : BeSpoke API function for New User Node request/response XML formate Data
	// History : 2012/09/11 Created by Lance Version 1, UnTest
	//----------------------------------------------------------
	include("mysql_connect.php");

	$xml = simplexml_load_file('php://input');
//	$xml = simplexml_load_file('userInfo.xml');
	
	//$array = $xml->attributes();
	
	foreach( $xml->attributes( ) as $attr)
	{
		$AttrArray[] = $attr;
	}
	
	$UserName = $AttrArray[0];
	$Password= $AttrArray[1];
	$Name = $AttrArray[2];
	$Level = $AttrArray[3];
	$Organization = $AttrArray[4];
	
	
    //Link to MySql
    
	if( strlen($UserName) != 0)
	{
    	$strSqlCommand = "SELECT count(*)
							FROM user
							WHERE Email = '".$UserName."'";
							
		$result = mysql_query($strSqlCommand);
		$rowUserInfo = @mysql_fetch_array($result);
		if ($rowUserInfo[0]!=0)
		{
			echo '<Registered Message="Account Registered" Domain="Configuration" />';
			exit;
		}
		
		$strSqlCommand = "INSERT INTO user (Name, Email, Password, Default_Channel, Enable, Level, Organization) VALUES ('".$Name."','".$UserName."','".$Password."','0','','iPadUser','".$Organization."')";
		if (!mysql_query($strSqlCommand))
 		{
	 		echo '<Error Message="The requested Information was not found" Domain="Configuration" />';
			saveError("AddUser", $UserName, date("Y-m-d H:i:s"), "The requested Information was not found");
			exit;
 		}
		
		echo '<Success Message="The requested Information was accepted" Domain="Configuration" />';
	}
	

?>